package project.hulpPakket;


import java.io.Serializable;


public class Vector3f extends Tuple3f implements Serializable
{
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
     * Constructs and initializes a Vector3f to (0,0,0).
     */

    public Vector3f()
    {
    }


    /**
     * Constructs and initializes a Vector3f from the specified xyz coordinates.
     * @param x
     * @param y
     * @param z
     */

    public Vector3f(float x, float y, float z)
    {
        super(x, y, z);
    }


    /**
     * Constructs and initializes a Vector3f from the specified Vector3f
     * @param v
     */

    public Vector3f(Vector3f v)
    {
        super(v);
    }


    /**
     * Constructs and initializes a Vector3f from the specified Vector3f.
     * @param t
     */

    public Vector3f(Tuple3f t)
    {
        super(t);
    }


    /**
     * Constructs and initializes a Vector3f from the array of length 3.
     * @param v
     */

    public Vector3f(float v[])
    {
        super(v);
    }
    /**
     * Defines a minus operation for two vectors
     */
    public static Vector3f Min(Vector3f v1, Vector3f v2)
    {
    	Vector3f v = new Vector3f(v1.x-v2.x, v1.y-v2.y,v1.z-v2.z);
    	return v;
    }
    /**
     * Defines a Plus operation for two vectors
     */
    public static Vector3f Plus(Vector3f v1, Vector3f v2)
    {
    	Vector3f v = new Vector3f(v1.x+v2.x, v1.y+v2.y,v1.z+v2.z);
    	return v;
    }
    /**
     * Defines an inproduct operation for two vectors
     */
    public static float Inp(Vector3f v1, Vector3f v2)
    {
    	return (v1.x*v2.x+v1.y*v2.y+v1.z*v2.z);
    }
    /**
     * Cross product for 2 vectors
     * @param v1
     * @param v2
     * @return
     */
    public static Vector3f cross(Vector3f v1, Vector3f v2)
    {
    	Vector3f v = new Vector3f(v1.y*v2.z-v1.z*v2.y,v1.z*v2.x-v1.x*v2.z,v1.x*v2.y-v1.y*v2.x);
    	return v;
    }
    /**
     * Scalar multiplication for a vector
     * @return 
     */
    public Vector3f multiply(float f)
    {
    	Vector3f copy = new Vector3f(this);
    	copy.x = x*f;
    	copy.y = y*f;
    	copy.z = z*f;
    	return copy;
    }
    /**
     * Scalar division for a vector
     * @return 
     */
    public Vector3f divide(float f)
    {
    	Vector3f copy = new Vector3f(this);
    	copy.x = x/f;
    	copy.y = y/f;
    	copy.z = z/f;
    	return copy;
    }
    
    /**
     *  Normalisation for a vector
     * @return 
     */
    public Vector3f normalise()
    {
    	Vector3f copy = new Vector3f(this);
    	float norm = Vector3f.Inp(copy, copy);
    	copy = copy.divide((float) Math.sqrt(norm));
    	return copy;
    }
}
